﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using dhDataAcess.produceLinq;

namespace dhDataAcess.produceDAL
{
   public  class cgddDetailDAL
    {
        
         string  tableName = "cgddDetail";
        private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public cgddDetailDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction ;
            conn = _conn;
        }
        /// <summary>
        /// 插入采购订单从表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int cgddDetailInsert(cgddDetailModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string insertstr = "insert into cgddDetail (mark,createDate,funit,fqty,unit,currency,acount,price,qty,matSpec,matNum,matName,billNo,greade,packmark,pihao,jhDate) values(@mark,@createDate,@funit,@fqty,@unit,@currency,@acount,@price,@qty,@matSpec,@matNum,@matName,@billNo,@greade,@packmark,@pihao,@jhDate)";
            //string insertstr = baseBLL.dTableColumnRead.insertSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                        new SqlParameter ("@mark",row .mark ),
                                        new SqlParameter ("@createDate",row .createDate ),
                                        new SqlParameter ("@funit",row .funit ),
                                        new SqlParameter ("@fqty",row .fqty ),
                                        new SqlParameter ("@unit",row .unit ),
                                        new SqlParameter ("@currency",row .currency ),
                                        new SqlParameter ("@price",row .price ),
                                        new SqlParameter ("@qty",row .qty ),
                                        new SqlParameter ("@matSpec",row .matSpec ),
                                        new SqlParameter ("@matNum",row .matNum ),
                                        new SqlParameter ("@billNo",row .billNo ),
                                        new SqlParameter ("@acount",row .acount ),
                                        new SqlParameter ("@matName",row .matName  ),
                                         new SqlParameter ("@greade",row .greade  ),
                                        new SqlParameter ("@packmark",row .packmark  ),
                                        new SqlParameter ("@pihao",row .pihao  ),
                                        new SqlParameter ("@jhDate",row.jhDate   )
                                    };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = insertstr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 更新采购订单从表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int cgddDetailUpdate(cgddDetailModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string updatestr = baseBLL.dTableColumnRead.updateSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                        new SqlParameter ("@mark",row .mark ),
                                        new SqlParameter ("@createDate",row .createDate ),
                                        new SqlParameter ("@funit",row .funit ),
                                        new SqlParameter ("@fqty",row .fqty ),
                                        new SqlParameter ("@unit",row .unit ),
                                        new SqlParameter ("@currency",row .currency ),
                                        new SqlParameter ("@price",row .price ),
                                        new SqlParameter ("@qty",row .qty ),
                                        new SqlParameter ("@matSpec",row .matSpec ),
                                        new SqlParameter ("@matNum",row .matNum ),
                                        new SqlParameter ("@billNo",row .billNo ),
                                       new SqlParameter ("@acount",row .acount ),
                                        new SqlParameter ("@matName",row .matName  ),
                                         new SqlParameter ("@greade",row .greade  ),
                                        new SqlParameter ("@packmark",row .packmark  ),
                                        new SqlParameter ("@pihao",row .pihao  ),
                                        new SqlParameter ("@jhDate",row.jhDate   )
                                    };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = updatestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行采购订单从表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int cgddDetailDel(string recordid)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deletestr = baseBLL.dTableColumnRead.delSqlStr (tableName).ToString();
            SqlParameter[] para = {
                                     
                                        new SqlParameter ("@recordid",recordid )
                                   };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = deletestr ;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
    }
}
